package com.ruoyi.peizhen.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.peizhen.domain.BusinessLabel;
import com.ruoyi.peizhen.service.IBusinessLabelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标签Controller
 * 
 * @author ruoyi
 * @date 2022-03-13
 */
@Controller
@RequestMapping("/peizhen/label")
public class BusinessLabelController extends BaseController
{
    private String prefix = "peizhen/label";

    @Autowired
    private IBusinessLabelService businessLabelService;

    @RequiresPermissions("peizhen:label:view")
    @GetMapping()
    public String label()
    {
        return prefix + "/label";
    }

    /**
     * 查询标签列表
     */
    @RequiresPermissions("peizhen:label:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusinessLabel businessLabel)
    {
        startPage();
        List<BusinessLabel> list = businessLabelService.selectBusinessLabelList(businessLabel);
        return getDataTable(list);
    }

    /**
     * 导出标签列表
     */
    @RequiresPermissions("peizhen:label:export")
    @Log(title = "标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusinessLabel businessLabel)
    {
        List<BusinessLabel> list = businessLabelService.selectBusinessLabelList(businessLabel);
        ExcelUtil<BusinessLabel> util = new ExcelUtil<BusinessLabel>(BusinessLabel.class);
        return util.exportExcel(list, "标签数据");
    }

    /**
     * 新增标签
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存标签
     */
    @RequiresPermissions("peizhen:label:add")
    @Log(title = "标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusinessLabel businessLabel)
    {
        return toAjax(businessLabelService.insertBusinessLabel(businessLabel));
    }

    /**
     * 修改标签
     */
    @RequiresPermissions("peizhen:label:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BusinessLabel businessLabel = businessLabelService.selectBusinessLabelById(id);
        mmap.put("businessLabel", businessLabel);
        return prefix + "/edit";
    }

    /**
     * 修改保存标签
     */
    @RequiresPermissions("peizhen:label:edit")
    @Log(title = "标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusinessLabel businessLabel)
    {
        return toAjax(businessLabelService.updateBusinessLabel(businessLabel));
    }

    /**
     * 删除标签
     */
    @RequiresPermissions("peizhen:label:remove")
    @Log(title = "标签", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(businessLabelService.deleteBusinessLabelByIds(ids));
    }
}
